/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainPanel.java
 *
 * Created on Sep 6, 2011, 7:29:30 AM
 */
package cw.ui;

import com.jtattoo.plaf.aero.AeroLookAndFeel;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author VinhTC
 */
public class MainPanel extends javax.swing.JFrame {

    /** Creates new form MainPanel */
    public MainPanel() {
        initComponents();
    }

    /**
     * ShowFrame
     * @param obj
     * @param title
     * @throws SecurityException
     */
    public void ShowFrame(JPanel obj, String title) throws SecurityException {
        JDialog frame = new JDialog();
        frame.setContentPane(obj);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setResizable(false);
        frame.setAlwaysOnTop(true);
        frame.setModal(true);
        frame.setTitle(title);
        frame.setLocationByPlatform(true);
        frame.pack();
        frame.setLocation(500, 200);
        frame.setSize(534, 450);
        frame.setVisible(true);
    }
    /**
     * ShowFrameAbout
     * @param obj
     * @param title
     * @throws SecurityException
     */
    public void ShowFrameAbout(JPanel obj, String title) throws SecurityException {
        JDialog frame = new JDialog();
        frame.setContentPane(obj);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setResizable(false);
        frame.setAlwaysOnTop(true);
        frame.setModal(true);
        frame.setTitle(title);
        frame.setLocationByPlatform(true);
        frame.pack();
        frame.setLocation(500, 200);

        frame.setSize(381, 210);
        frame.setVisible(true);
    }
    /**
     * ShowFrameAbout
     * @param obj
     * @param title
     * @throws SecurityException
     */
    public void ShowFrameConfig(JPanel obj, String title) throws SecurityException {
        JDialog frame = new JDialog();
        frame.setContentPane(obj);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setResizable(false);
        frame.setAlwaysOnTop(true);
        frame.setModal(true);
        frame.setTitle(title);
        frame.setLocationByPlatform(true);
        frame.pack();
        frame.setLocation(500, 200);

        frame.setSize(440, 250);
        frame.setVisible(true);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jbtnNewGame = new javax.swing.JButton();
        jbtnHighScore = new javax.swing.JButton();
        jbtnAboutUs = new javax.swing.JButton();
        jbtnHelp = new javax.swing.JButton();
        jbtnQuit = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("CrossWords - MainPanel");
        setResizable(false);

        jPanel1.setOpaque(false);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/PuzzleLogo.png"))); // NOI18N

        jbtnNewGame.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
        jbtnNewGame.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/calculate.png"))); // NOI18N
        jbtnNewGame.setText("New Game");
        jbtnNewGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNewGameActionPerformed(evt);
            }
        });

        jbtnHighScore.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
        jbtnHighScore.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/hightscore.png"))); // NOI18N
        jbtnHighScore.setText("High Score");
        jbtnHighScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnHighScoreActionPerformed(evt);
            }
        });

        jbtnAboutUs.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
        jbtnAboutUs.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/info-16.png"))); // NOI18N
        jbtnAboutUs.setText("About us");
        jbtnAboutUs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAboutUsActionPerformed(evt);
            }
        });

        jbtnHelp.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
        jbtnHelp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/help2.png"))); // NOI18N
        jbtnHelp.setText("Help");
        jbtnHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnHelpActionPerformed(evt);
            }
        });

        jbtnQuit.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12));
        jbtnQuit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit2.png"))); // NOI18N
        jbtnQuit.setText("Quit");
        jbtnQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnQuitActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 11));
        jButton1.setForeground(new java.awt.Color(204, 51, 0));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/basket_put.png"))); // NOI18N
        jButton1.setText("Setting Connection");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(228, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jbtnQuit, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                        .addComponent(jbtnHelp, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                        .addComponent(jbtnAboutUs, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                        .addComponent(jbtnHighScore, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                        .addComponent(jbtnNewGame, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)))
                .addGap(213, 213, 213))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addGap(28, 28, 28)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnNewGame, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnHighScore, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnAboutUs, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnQuit, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63))
        );

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MainPanelBg.png"))); // NOI18N
        jLabel1.setOpaque(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnNewGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNewGameActionPerformed
        PlayerSettingGame newgame = new PlayerSettingGame();

        newgame.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jbtnNewGameActionPerformed

    private void jbtnHighScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHighScoreActionPerformed
        ShowFrame(new HighScores(), "Cross Words - High score");
    }//GEN-LAST:event_jbtnHighScoreActionPerformed

    private void jbtnAboutUsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAboutUsActionPerformed
        ShowFrameAbout(new About(), "Cross Words - About us");
    }//GEN-LAST:event_jbtnAboutUsActionPerformed

    private void jbtnQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnQuitActionPerformed
        int index = JOptionPane.showConfirmDialog(jbtnQuit, "Are you sure want to quit game?", "Confirm for quit game", JOptionPane.YES_NO_OPTION);
        if (index == 0) {
            System.exit(0);
        }
    }//GEN-LAST:event_jbtnQuitActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ShowFrameConfig(new ConfigConnectServer(), "Cross Words - Config connection to server");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jbtnHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHelpActionPerformed
        // TODO add your handling code here:
        try {
            Desktop.getDesktop().open(new File("src/Docs/UserGuide.chm"));
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "User guide is not available");
        }
    }//GEN-LAST:event_jbtnHelpActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel(new AeroLookAndFeel());
                    new MainPanel().setVisible(true);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jbtnAboutUs;
    private javax.swing.JButton jbtnHelp;
    private javax.swing.JButton jbtnHighScore;
    private javax.swing.JButton jbtnNewGame;
    private javax.swing.JButton jbtnQuit;
    // End of variables declaration//GEN-END:variables
}
